import request from "@/utils/service"
import type * as ILogin from "./types/login"

/** 获取header的access_token */
export function loginTokenApi(params: ILogin.ILoginTokenRequestData) {
  return request<ILogin.LoginTokenResponseData>({
    url: "/accessToken",
    method: "get",
    params
  })
}

/** 是否登录成功 */
export function loginApi(data: ILogin.ILoginRequestData) {
  return request<ILogin.LoginResponseData<string>>({
    url: "/api/v2/login/login",
    method: "post",
    data
  })
}

/** 获取用户详情 */
export function getUserInfoApi() {
  return request<ILogin.UserInfoResponseData>({
    url: "/api/v2/login/login",
    method: "get"
  })
}

/** 退出登录 */
export function userLoginOutApi() {
  return request<ILogin.LoginResponseData<any>>({
    url: "/api/v2/login/logout",
    method: "delete"
  })
}

/** 第一次登录修改密码 */
export function editLoginPwdApi(data: { user_password: string }) {
  return request<ILogin.LoginResponseData<any>>({
    url: "/api/v2/login/editPassword",
    method: "put",
    data
  })
}

/** 管理员重置他人密码 并重置第一次登陆状态 */
export function resetLoginPwdApi(data: { id: number }) {
  return request<ILogin.LoginResponseData<any>>({
    url: "/api/v2/login/resetLogin",
    method: "put",
    data
  })
}
/** 获取系统版本号 */
export function getSystemVersionApi() {
  return request<ILogin.LoginResponseData<ILogin.IVersionData>>({
    url: "/api/v2/area/getAreaVersion",
    method: "get"
  })
}
